package com.macaline.filter;

import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;
/**
 * 组件注册过滤器
 * @author warm_joy
 */
public class ComponetFilter implements TypeFilter {

	@Override
	public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
			throws IOException {
		// 获取当前扫描类的注解信息
		@SuppressWarnings("unused")
		AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
		// 获取当前正在扫描的类的类信息
		ClassMetadata classMetadata = metadataReader.getClassMetadata();
		String className = classMetadata.getClassName();
		if(className.indexOf("abb") == -1 || className.indexOf("edis") == -1) {
			return true;
		}
		
		String path = metadataReader.getResource().getURI().getPath();
		if(path.indexOf("rabb") == -1 || path.indexOf("redis") == -1 ) {
			System.out.println("过滤器" + classMetadata.getClassName());
			return true;
		}
		System.out.println("过滤不注入的类名" + className);
		return false;
	}

}
